<template>
  <page-wrap :show-top="false" :title="title" bgColor="#ffffff" hideTab :back="false">
    <view class="wrapper">
      <web-view :src="linkUrl" @touchstart="onTouchStart" @touchmove="onTouchMove" @touchend="onTouchEnd"></web-view>
    </view>
  </page-wrap>
</template>

<script>
import ShareMixin from "@/mixins/share";
export default {
  mixins: [ShareMixin],
  data() {
    return {
      linkUrl: "",
      title: "",
    };
  },
  onLoad(opt) {
    wx.hideHomeButton();
    this.linkUrl = decodeURIComponent(opt.link);
    this.title = opt.title;
    let title = opt.title;
    uni.setNavigationBarTitle({
      title: title,
    });
    uni.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: this.$primaryColor,
    });

    this.shareTitle = this.title;
    this.sharePath = `/pagesSub/public/web/index?title=${
      this.title
    }&link=${encodeURIComponent(this.linkUrl)}`;
    this.shareQuery = `title=${this.title}&link=${encodeURIComponent(
      this.linkUrl
    )}`;
  },
  methods: {
    onTouchStart(event) {
      // 获取触摸起始横坐标
      this.startX = event.changedTouches[0].pageX;
    },
    onTouchMove(event) {
      // 获取当前横坐标
      const currentX = event.changedTouches[0].pageX;
      // 判断滑动方向 // 也不知道能不能生效，不生效就算了
      if (currentX - this.startX > 0) {
        uni.navigateBack();
      }
    },
    onTouchEnd() {
      // 清空起始横坐标
      this.startX = 0;
    },
  },
};
</script>

<style lang="scss">
.page-wrap {
  background: $uni-bg-color;
}
</style>
